package week05;



import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	public int compareTo(PersonSortable o){
		if(this.name.compareTo(o.name)==0){
			if(this.age==o.age)
				return 0;
			if(this.age>o.age)
				return 1;
			if(this.age<o.age)
				return -1;
		}
		return name.compareTo(o.name);
		
	}
	
	public PersonSortable(String name,int age) {
		this.name = name;
		this.age =age;
	}

	@Override
	public String toString() {
		return  name+"-"+age;
	}
	

	
}

public class Pta1 {
	public static void main(String[] args) {
		//Student[] stus = new Student[2];
		Scanner sc=new Scanner (System.in);
		int n=sc.nextInt();
		PersonSortable[] stus = new PersonSortable[n];
		for(int i=0;i<n;i++)
		{//stus[0] = new Student("zhang");
		//stus[1] = new Student("wang");
		stus[i] = new PersonSortable(sc.next(),sc.nextInt());
		}
		Arrays.sort(stus);
		for(int i=0;i<n;i++){
			System.out.println(stus[i]);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}
}
